﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skynet.WebSupport.Views.PerformanceMgm;
using Microsoft.Practices.Unity;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Threading;
using System.Web.UI.DataVisualization.Charting; 
namespace Skynet.WebSite.Support
{
    public partial class PerformanceMgmView : Skynet.WebFoundation.Views.Page, IPerformanceMgmView
    {
        private PerformanceMgmPresenter _Presenter;
        [Dependency]
        public PerformanceMgmPresenter Presenter
        {
            get { return _Presenter; }
            set
            {
                _Presenter = value;
                this._Presenter.View = this;
            }
        }
        protected override void OnPreInit(EventArgs e)
        {
            
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
//            this.odsAdoPerfCounters.ObjectCreating += delegate(object ocds, ObjectDataSourceEventArgs args) { args.ObjectInstance = this.Presenter; };              
            if (!Page.IsPostBack)
                this.Presenter.OnViewInitialized();
            else
                this.Presenter.OnViewLoaded();         
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 20; i++)
            {
                
                var sql = new SqlConnection("data source=skynetlibrary; Integrated security=SSPI;Initial Catalog=SkynetLibrary;Asynchronous Processing=true; MultipleActiveResultSets=True; Pooling=false;");
                sql.Open();
                Thread.Sleep(100);
                //Application[Guid.NewGuid().ToString()] = sql;
                sql.Close();
            }
            
        }

        public string InstanceName
        {
            set {
                this.lblProcessName.Text = value; 
            }
        }


     

        protected void tRefresh_Tick(object sender, EventArgs e)
        {
            this.Presenter.LoadCounters(); 
        }
        public List<Tuple<string, float>> AdoPerformanceCounters
        {
            set {
                ChartArea area = new ChartArea("AdoPerformance Counters");
                this.mscAdoPerf.ChartAreas.Add(area);             
                area.AxisX.Title = "Performance Counters";
                Series series = new Series("Spline");
                series.ChartType = SeriesChartType.StackedColumn100;
                series.BorderWidth = 3;
                series.ShadowOffset = 2;

                series.XValueType = ChartValueType.String; 
                

                //var count = 0;
                //foreach (var item in value)
                //{
                //    count++;
                //    series.Points.AddXY(item.Item1, (double)item.Item2);
                //}

                //area.AxisX.LabelStyle.TruncatedLabels = true; 





                double[] yValues = { 12, 67, 45, double.NaN, 67, 89, 35, 12, 78, 54 };
                string[] xValues = { "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999" };
                ////series.Points.DataBindXY(xValues, yValues);
                for (int i = 0; i < xValues.Count(); i++)
                {
                    series.Points.AddXY(xValues.ElementAt(i), yValues.ElementAt(i));
                }



                this.mscAdoPerf.Series.Add(series);                
            }
        }
    }
}